____ _ _ _ _
| _ \ ___ | |_ (_) _ __ ___ __| | (_) __ _
| |_) | / _ \ | __| | | | '_ \ / _ \ / _| | | | / _ |
| _ < | __/ | |_ | | | |_) | | __/ | (_| | | | | (_| |
|_| \_\ \___| \__| |_| | .__/ \___| \__,_| |_| \__,_|
|_|
- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b
Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―
Chomsky-Normalform
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
top
Die Chomsky-Normalform (Abk.: CNF) ist in der theoretischen Informatik eine Normalform fΓΌr kontextfreie Grammatiken. Sie ist nach dem Linguisten Noam Chomsky benannt und kommt beim CYK-Algorithmus zum Einsatz. Eine kontextfreie Grammatik in Chomsky-Normalform hat eine einfache Struktur der Produktionsregeln und erfΓΌllt auch die Eigenschaften kontextsensitiver Grammatiken.
Zu jeder kontextfreien Sprache gibt es eine Grammatik in Chomsky-Normalform. Aus jeder kontextfreien Grammatik G {\displaystyle G} kann eine Grammatik G C N F {\displaystyle G_{CNF}} in Chomsky-Normalform konstruiert werden, die dieselbe Sprache erzeugt. Die Grammatik G C N F {\displaystyle G_{CNF}} wird dann auch eine Chomsky-Normalform der kontextfreien Grammatik G {\displaystyle G} genannt.
Eine weitere Normalform fΓΌr kontextfreie Grammatiken ist die Greibach-Normalform. Eine Erweiterung der Chomsky-Normalform auf kontextsensitive Grammatiken stellt die Kuroda-Normalform dar. Die Chomsky-Normalform wird auf Grund der gleichen AbkΓΌrzung leicht mit der Konjunktiven Normalform (engl. conjunctive normal form) verwechselt.
Contents
β’ Definition
β’ Beispiel
β’ Quellen
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Definition
Eine formale Grammatik G = ( V , Ξ£ Ξ£ , P , S ) {\displaystyle G=(V,\Sigma ,P,S)} ist in Chomsky-Normalform, wenn jede Produktion aus P {\displaystyle P} eine der folgenden Formen hat:
β’ A β β B C {\displaystyle A\rightarrow BC}
β’ A β β a {\displaystyle A\rightarrow a}
β’ S β β Ξ΅ Ξ΅ {\displaystyle S\rightarrow \varepsilon }
wobei A {\displaystyle A} , B {\displaystyle B} und C {\displaystyle C} Nichtterminalsymbole aus V {\displaystyle V} sind und a {\displaystyle a} ein Terminalsymbol aus Ξ£ Ξ£ {\displaystyle \Sigma } ist. S {\displaystyle S} ist das Startsymbol und Ξ΅ Ξ΅ {\displaystyle \varepsilon } das leere Wort. Wenn die Produktion S β β Ξ΅ Ξ΅ {\displaystyle S\rightarrow \varepsilon } zur Grammatik gehΓΆrt, dann darf S {\displaystyle S} nicht auf der rechten Seite einer Produktion stehen.
LΓ€sst man bei der ersten Produktion auf der rechten Seite beliebig viele anstatt zwei Nichtterminalsymbole zu, so spricht man von einer schwachen Chomsky-Normalform.
Konstruktion einer Chomsky-Normalform
Liegt eine kontextfreie Grammatik G = ( V , Ξ£ Ξ£ , P , S ) {\displaystyle G=(V,\Sigma ,P,S)} vor, so lΓ€sst sich daraus schrittweise eine Grammatik G β² {\displaystyle G'} in Chomsky-Normalform generieren, die dieselbe Sprache erzeugt:
Ausnahme S β β Ξ΅ Ξ΅ {\displaystyle S\rightarrow \varepsilon } behandeln
EnthΓ€lt die Grammatik G {\displaystyle G} die Regel S β β Ξ΅ Ξ΅ {\displaystyle S\rightarrow \varepsilon } , wird ein neues Startsymbol S β² {\displaystyle S'} fΓΌr G β² {\displaystyle G'} eingefΓΌhrt. AnschlieΓend erhΓ€lt die neue Grammatik die Regeln S β² β β Ξ΅ Ξ΅ {\displaystyle S'\rightarrow \varepsilon } und S β² β β S {\displaystyle S'\rightarrow S} . Damit ist sichergestellt, dass die Grammatik weiterhin das leere Wort ermΓΆglicht und das ursprΓΌngliche Startsymbol weiterhin auf der rechten Seite verwendet werden kann.
Eine schwache Chomsky-Normalform erzeugen
Jedem Terminalsymbol a {\displaystyle a} wird ein Nichtterminalsymbol X a {\displaystyle X_{a}} zugeordnet. Auf der rechten Seite jeder Produktion werden sΓ€mtliche Terminalsymbole a {\displaystyle a} durch das entsprechende Nichtterminalsymbol X a {\displaystyle X_{a}} ersetzt. AbschlieΓend werden alle Produktionen X a β β a {\displaystyle X_{a}\rightarrow a} der Grammatik hinzugefΓΌgt.
Rechte Seiten mit mehr als zwei Nichtterminalen ersetzen
Sind auf der rechten Seite einer Produktion mehr als zwei Nichtterminale, so werden zwei benachbarte Nichtterminale A B {\displaystyle AB} durch ein neues Nichtterminal Y A B {\displaystyle Y_{AB}} ersetzt. Die Produktion Y A B β β A B {\displaystyle Y_{AB}\rightarrow AB} wird zur Grammatik hinzugefΓΌgt. Dies wiederholt man solange, bis keine Produktion mit mehr als zwei Nichtterminalen mehr vorkommt.
Ξ΅ Ξ΅ {\displaystyle \varepsilon } -Produktionen entfernen
Streiche die Regeln A β β Ξ΅ Ξ΅ {\displaystyle A\rightarrow \varepsilon } , auΓer S β² β β Ξ΅ Ξ΅ {\displaystyle S'\rightarrow \varepsilon } (falls vorhanden).
Gab es vorher genau eine Produktion mit A {\displaystyle A} auf der linken Seite, so streiche das A {\displaystyle A} ΓΌberall auf den rechten Seiten der Produktionen, denn es kann nicht zu einem Terminal abgeleitet werden.
Gab es vorher mehrere Produktionen mit A {\displaystyle A} auf der linken Seite, so fΓΌge fΓΌr jede Regel, die ein solches A {\displaystyle A} auf der rechten Seite enthΓ€lt, eine Regel hinzu, in der das A {\displaystyle A} gestrichen wurde, denn es muss der Fall betrachtet werden, in dem das A {\displaystyle A} als leeres Wort abgeleitet wurde oder etwa nicht. Die Regel C β β A B {\displaystyle C\rightarrow AB} wird dann beispielsweise um die Regel C β β B {\displaystyle C\rightarrow B} ergΓ€nzt.
Aus C β β A B {\displaystyle C\rightarrow AB} wird also:
C β β B {\displaystyle C\rightarrow B}
C β β A B {\displaystyle C\rightarrow AB}
Kettenregeln (Produktionen der Form AβB) entfernen
Wenn man eine Kettenregel, d. h. eine Produktion der Form A β β B {\displaystyle A\rightarrow B} , entfernt, fΓΌgt man fΓΌr jede vorhandene Produktion der Form B β β w {\displaystyle B\rightarrow w} eine neue Produktion A β β w {\displaystyle A\rightarrow w} hinzu, falls diese keine bereits entfernte Kettenregel ergibt. w {\displaystyle w} ist hierbei ein beliebiges Wort; die vorangegangenen Γnderungen gewΓ€hrleisten aber, dass w {\displaystyle w} entweder genau ein Terminalsymbol ist oder ein Wort aus genau zwei Nichtterminalsymbolen.
Beispiel
Es gilt, die Grammatik ΓΌber dem Alphabet Ξ£ Ξ£ = { a , b } {\displaystyle \Sigma =\{a,b\}} mit den Regeln
β’ S β β A S A | a B {\displaystyle S\rightarrow ASA|aB}
β’ A β β B | S {\displaystyle A\rightarrow B|S}
β’ B β β b | Ξ΅ Ξ΅ {\displaystyle B\rightarrow b|\varepsilon }
in Chomsky-Normalform zu bringen.
1. Neue Startvariable hinzufΓΌgen
β’ S 0 β β S {\displaystyle S_{0}\rightarrow S}
β’ S β β A S A | a B {\displaystyle S\rightarrow ASA|aB}
β’ A β β B | S {\displaystyle A\rightarrow B|S}
β’ B β β b | Ξ΅ Ξ΅ {\displaystyle B\rightarrow b|\varepsilon }
2. Ξ΅ Ξ΅ {\displaystyle \varepsilon } -ΓbergΓ€nge entfernen
β’ S 0 β β S {\displaystyle S_{0}\rightarrow S}
β’ S β β A S A | a B | a {\displaystyle S\rightarrow ASA|aB|a}
β’ A β β B | Ξ΅ Ξ΅ | S {\displaystyle A\rightarrow B|\varepsilon |S}
β’ B β β b {\displaystyle B\rightarrow b}
Eine neue Ξ΅ Ξ΅ {\displaystyle \varepsilon } -Regel ist entstanden, die wiederum gleich behandelt werden muss:
β’ S 0 β β S {\displaystyle S_{0}\rightarrow S}
β’ S β β A S A | A S | S A | a B | a {\displaystyle S\rightarrow ASA|AS|SA|aB|a}
β’ A β β B | S {\displaystyle A\rightarrow B|S}
β’ B β β b {\displaystyle B\rightarrow b}
3. Alle Einheits-Regeln entfernen. Diese sind A β β B , A β β S {\displaystyle A\rightarrow B,A\rightarrow S} und S 0 β β S {\displaystyle S_{0}\rightarrow S} .
β’ S 0 β β S {\displaystyle S_{0}\rightarrow S}
β’ S β β A S A | A S | S A | a B | a {\displaystyle S\rightarrow ASA|AS|SA|aB|a}
β’ A β β S {\displaystyle A\rightarrow S}
β’ B β β b {\displaystyle B\rightarrow b}
β’ A β β b {\displaystyle A\rightarrow b}
danach A β β S {\displaystyle A\rightarrow S}
β’ S 0 β β S {\displaystyle S_{0}\rightarrow S}
β’ S β β A S A | A S | S A | a B | a {\displaystyle S\rightarrow ASA|AS|SA|aB|a}
β’ A β β A S A | A S | S A | a B | a | b {\displaystyle A\rightarrow ASA|AS|SA|aB|a|b}
β’ B β β b {\displaystyle B\rightarrow b}
und zum Schluss S 0 β β S {\displaystyle S_{0}\rightarrow S}
β’ S 0 β β A S A | A S | S A | a B | a {\displaystyle S_{0}\rightarrow ASA|AS|SA|aB|a}
β’ S β β A S A | A S | S A | a B | a {\displaystyle S\rightarrow ASA|AS|SA|aB|a}
β’ A β β A S A | A S | S A | a B | a | b {\displaystyle A\rightarrow ASA|AS|SA|aB|a|b}
β’ B β β b {\displaystyle B\rightarrow b}
4. LΓ€ngere Verkettungen sind nicht erlaubt, deshalb fΓΌhren wir eine zusΓ€tzliche Variable A 1 {\displaystyle A_{1}} ein und ersetzen S β β A S A {\displaystyle S\rightarrow ASA} durch die Regel S β β A A 1 {\displaystyle S\rightarrow AA_{1}} und A 1 β β S A {\displaystyle A_{1}\rightarrow SA} :
β’ S 0 β β A A 1 | A S | S A | a B | a {\displaystyle S_{0}\rightarrow AA_{1}|AS|SA|aB|a}
β’ S β β A A 1 | A S | S A | a B | a {\displaystyle S\rightarrow AA_{1}|AS|SA|aB|a}
β’ A β β A A 1 | A S | S A | a B | a | b {\displaystyle A\rightarrow AA_{1}|AS|SA|aB|a|b}
β’ A 1 β β S A {\displaystyle A_{1}\rightarrow SA}
β’ B β β b {\displaystyle B\rightarrow b}
Nun bleiben nur noch die Regeln A β β a B {\displaystyle A\rightarrow aB} und S β β a B {\displaystyle S\rightarrow aB} . Deshalb wird eine weitere Variable X a {\displaystyle X_{a}} verwendet, die zusammen mit der Regel X a β β a {\displaystyle X_{a}\rightarrow a} das Terminalsymbol a {\displaystyle a} in den genannten Regeln ersetzen kann.
β’ S 0 β β A A 1 | A S | S A | X a B | a {\displaystyle S_{0}\rightarrow AA_{1}|AS|SA|X_{a}B|a}
β’ S β β A A 1 | A S | S A | X a B | a {\displaystyle S\rightarrow AA_{1}|AS|SA|X_{a}B|a}
β’ A β β A A 1 | A S | S A | X a B | a | b {\displaystyle A\rightarrow AA_{1}|AS|SA|X_{a}B|a|b}
β’ A 1 β β S A {\displaystyle A_{1}\rightarrow SA}
β’ X a β β a {\displaystyle X_{a}\rightarrow a}
β’ B β β b {\displaystyle B\rightarrow b}
Somit ist die Grammatik in Chomsky-Normalform umgewandelt.
Quellen
β’ Grzegorz Rozenberg, Arto Salomaa: Handbook of Formal Languages. Volume 1: Word, Language, Grammar. Springer-Verlag, Berlin u. a. 1997, ISBN 3-540-60420-0, S. 124β125